package com.ruoyi.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.CampUser;
import com.ruoyi.wechat.service.ICampUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 露营用户Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/camp/user")
public class CampUserController extends BaseController
{
    @Autowired
    private ICampUserService campUserService;

    /**
     * 查询露营用户列表
     */
//    @PreAuthorize("@ss.hasPermi('wechart:camp_user:list')")
    @GetMapping("/list")
    public TableDataInfo list(CampUser campUser)
    {
        startPage();
        List<CampUser> list = campUserService.selectCampUserList(campUser);
        return getDataTable(list);
    }
    /**
     * 查询露营用户列表
     */
//    @PreAuthorize("@ss.hasPermi('wechart:camp_user:list')")
    @GetMapping("/getAll")
    public AjaxResult getAll(CampUser campUser)
    {
        List<CampUser> list = campUserService.selectCampUserList(campUser);
        return AjaxResult.success(list);
    }

    /**
     * 导出露营用户列表
     */
    @PreAuthorize("@ss.hasPermi('wechart:camp_user:export')")
    @Log(title = "露营用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CampUser campUser)
    {
        List<CampUser> list = campUserService.selectCampUserList(campUser);
        ExcelUtil<CampUser> util = new ExcelUtil<CampUser>(CampUser.class);
        util.exportExcel(response, list, "露营用户数据");
    }

    /**
     * 获取露营用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('wechart:camp_user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") String userId)
    {
        return success(campUserService.selectCampUserByUserId(userId));
    }

    /**
     * 新增露营用户
     */
    @PreAuthorize("@ss.hasPermi('wechart:camp_user:add')")
    @Log(title = "露营用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CampUser campUser)
    {
        return toAjax(campUserService.insertCampUser(campUser));
    }

    /**
     * 修改露营用户
     */
    @PreAuthorize("@ss.hasPermi('wechart:camp_user:edit')")
    @Log(title = "露营用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CampUser campUser)
    {
        return toAjax(campUserService.updateCampUser(campUser));
    }

    /**
     * 删除露营用户
     */
    @PreAuthorize("@ss.hasPermi('wechart:camp_user:remove')")
    @Log(title = "露营用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable String[] userIds)
    {
        return toAjax(campUserService.deleteCampUserByUserIds(userIds));
    }
}
